<template>
    <div class="center">
        <pub-head isBorder="true"></pub-head>
        
        <div class="user-box flex">
            <div class="user-info flexc">
                <router-link :to="'/userInfo'" class="flexv">
                    <div class="user-img flex">
                        <img :src="user.avatar" alt="">
                    </div>
                    <p class="user-name">{{user.nickname}}</p>
                </router-link>
            </div>
        </div>

        <!-- 按钮列表 -->
        <div class="user-btns flexv">
            <router-link :to="'/business'" class="user-btn">业务查询</router-link>
            <router-link :to="'/feedBack'" class="user-btn">意见反馈</router-link>
            <router-link :to="'/set'" class="user-btn">我的设置</router-link>
            <router-link :to="'/aboutUs'" class="user-btn">关于我们</router-link>
        </div>

        <!-- 退出登录 -->
        <div class="logout" @click="logout">退出登录</div>

        <!-- 底部占位符 -->
        <div class="pub-foot-seat"></div>

        <pub-foot center="true"></pub-foot>
    </div>
</template>
<script>
import Vue from 'vue'
import { mapState } from 'vuex';
import pubHead from '@/components/head'
import pubFoot from '@/components/foot'
import { Dialog, Toast } from 'vant';

Vue.use(Dialog)
export default {
    data() {
        return{
            user: [], // 用户信息
        }
    },
    created(){
        this.axios.get('http://jxjq.0791jr.com/index.php?m=App&c=Mine&a=index', {
            params: {
                uid: this.$store.state.user.uid
            }
        }).then(res => {
            if(res.status == 200){
                const data = res.data.data;
                this.user = data.user_info;
            }
        })
    },
    computed: {
        ...mapState(['user'])
    },
    components: {
        pubHead,
        pubFoot
    },
    methods: {
        logout(){
            Dialog.confirm({
                title: '您确定要退出登录吗？'
                }).then(() => {
                    // on confirm
                    this.$router.replace('/login');
                    sessionStorage.clear();
                }).catch(() => {
                    // on cancel
                    Dialog.close
            });
        }
    }
}
</script>
<style lang="less" scoped>
.center {
    min-height: 100vh;
    background-color: #fff;
    .user-box {
        width: 100%;
        height: 3.7rem;
        background: url('~@/assets/images/center-bg.png') no-repeat;
        background-size: 100%;
        .user-info {
            width: 6.76rem;
            height: 2.8rem;
            margin: 0.74rem auto auto;
            border-radius: 0.2rem;
            background: url('~@/assets/images/user-bg.png') no-repeat;
            background-size: 100%;
            .user-img {
                width: 1.3rem;
                height: 1.3rem;
                margin: 0 auto;
                border-radius: 100%;
                border: 1px solid #dfdfdf;
                overflow: hidden;
                cursor: pointer;
            }
            .user-name {
                margin-top: 0.1rem;
                font-size: 0.32rem;
                text-align: center;
                line-height: 150%;
                font-weight: bold;
                color: #333;
                cursor: pointer;
            }
        }
    }

    // 设置
    .user-btns {
        padding: 0 0.4rem;
        .user-btn {
            width: 100%;
            height: 1rem;
            border-bottom: 1px solid #dbdbdb;
            font-size: 0.28rem;
            line-height: 0.99rem;
            font-weight: bold;
            color: #333;
            background: url('~@/assets/to.png') no-repeat right center;
            background-size: 0.12rem 0.24rem;
            display: block;
            cursor: pointer;
        }
    }

    // 退出
    .logout {
        width: 7rem;
        height: 0.86rem;
        margin: 0.3rem auto auto;
        border-radius: 0.1rem;
        font-size: 0.26rem;
        line-height: 0.86rem;
        text-align: center;
        color: #fff;
        background-color: #1f78ff;
        cursor: pointer;
    }
    .pub-foot-seat {
        width: 100%;
        height: 0.98rem;
    }
}
</style>
